<template>
  <div class="app-container">
    <div>
      <el-input
        v-model="userViewModel.UserName"
        size="small"
        placeholder="姓名"
        style="width: 200px;"
        class="filter-item"
        @keyup.enter.native="queryUser"
      />
      <el-input
        v-model="userViewModel.LoginName"
        size="small"
        placeholder="登录名"
        style="width: 200px;"
        class="filter-item"
        @keyup.enter.native="queryUser"
      />
      <el-input
        v-model="userViewModel.MobilePhone"
        size="small"
        placeholder="手机号"
        style="width: 200px;"
        class="filter-item"
        @keyup.enter.native="queryUser"
      />
      <el-button type="primary" @click="queryUser" size="small" icon="el-icon-search">查询</el-button>
      <el-button type="primary" @click="handleAdd" size="small" icon="el-icon-plus">新增</el-button>
      <el-button type="primary" @click="refreshUser" size="small" icon="el-icon-refresh">刷新</el-button>
      <el-button
        v-waves
        style="margin-left: 10px;"
        size="small"
        class="filter-item"
        type="primary"
        icon="el-icon-upload"
        @click="handlesgmwUpload"
      >导入用户信息</el-button>
    </div>
    <el-table
      v-loading="loading"
      :header-cell-style="{background:'#eef1f6',color:'#606266'}"
      :data="SGMWuserList"
      style="width: 100%;margin-top:30px;"
      height="630"
      border
      @sort-change="sortChange"
    >
      <el-table-column label="姓名" show-overflow-tooltip>
        <template slot-scope="scope">{{ scope.row.UserName }}</template>
      </el-table-column>
      <el-table-column label="登录名" show-overflow-tooltip>
        <template slot-scope="scope">{{ scope.row.LoginName }}</template>
      </el-table-column>
      <el-table-column label="手机号" show-overflow-tooltip>
        <template slot-scope="scope">{{ scope.row.MobilePhone }}</template>
      </el-table-column>
      <!-- <el-table-column label="邀请码">
        <template slot-scope="scope">{{ scope.row.InviteCode }}</template>
      </el-table-column>-->
      <el-table-column label="生日" show-overflow-tooltip>
        <template slot-scope="scope">{{ scope.row.BirthdayStr}}</template>
      </el-table-column>
      <el-table-column label="注册时间" sortable="custom" prop="CreateTime">
        <template slot-scope="scope">{{ scope.row.CreateTime}}</template>
      </el-table-column>
      <el-table-column align="center" width="240" label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="mini" @click="handleEdit(scope)" icon="el-icon-edit">编辑</el-button>
          <el-button type="text" size="mini" @click="handleDelete(scope)" icon="el-icon-delete">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件：https://element.eleme.cn/#/zh-CN/component/pagination -->
    <div class="block" style="float:right;margin-top:15px;" v-if="userViewModel.total>0">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="userViewModel.page"
        :page-sizes="[10, 20, 30, 40,100]"
        :page-size="userViewModel.pageSize"
        @prev-click="lastPage"
        @next-click="nextPage"
        background
        layout="total, sizes, prev, pager, next, jumper"
        :total="userViewModel.total"
      ></el-pagination>
    </div>
    <el-dialog
      :visible.sync="dialogVisible"
      :title="dialogType==='edit'?'编辑用户':'新增用户'"
      width="50%"
      top="3vh"
      :close-on-click-modal="false"
    >
      <el-form
        :model="user"
        ref="user"
        :rules="rules"
        label-width="80px"
        label-position="right"
        style="width: 90%;"
      >
        <el-row>
          <el-col :span="24">
            <el-form-item label="登录名" prop="LoginName">
              <el-input v-model="user.LoginName" :disabled="dialogType==='edit'" placeholder="登录名">
                <!-- <template slot="append">@qdlsai.org</template> -->
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="姓名" prop="UserName">
              <el-input v-model="user.UserName" placeholder="姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="学校" prop="OrgCode">
              <el-select v-model="user.OrgCode" placeholder="请选学校" style="width:100%">
                <el-option
                  v-for="item in allOrg"
                  :key="item.org_code"
                  :label="item.org_name"
                  :value="item.org_code"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="头像" prop="HeadPhoto">
              <el-upload
                class="avatar-uploader"
                id="uploadimginput"
                :action="actionUrl"
                :show-file-list="false"
                :on-success="handleAvatarSuccess"
                :before-upload="beforeAvatarUpload"
              >
                <img v-if="user.ShowHeadPhoto" :src="user.ShowHeadPhoto" class="avatar" />
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="密码" prop="Password">
              <el-input v-model="user.Password" type="password" placeholder="密码" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="确认密码" prop="ConfirmPassword">
              <el-input v-model="user.ConfirmPassword" type="password" placeholder="确认密码" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="移动电话" prop="MobilePhone">
              <el-input v-model="user.MobilePhone" placeholder="移动电话" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="职务" prop="Position">
              <el-input v-model="user.Position" placeholder="职务" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="邮箱" prop="Email">
              <el-input v-model="user.Email" placeholder="邮箱" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="出生日期" prop="Birthday">
              <el-date-picker
                v-model="user.Birthday"
                style="width: 100%;"
                type="date"
                format="yyyy-MM-dd"
                placeholder="出生日期"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="分配套餐" prop="PackageIdList">
              <el-select
                v-model="user.PackageIdList"
                filterable
                multiple
                placeholder="请选套餐"
                style="width:100%"
              >
                <el-option
                  v-for="item in allPackages"
                  :key="item.Id"
                  :label="item.Name"
                  :value="item.Id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="性别" prop="Sex">
              <template>
                <el-radio-group v-model="user.Sex">
                  <el-radio v-for="item in sexList" :label="item" :key="item">{{item}}</el-radio>
                </el-radio-group>
              </template>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="个人简介">
              <el-input
                :autosize="{ minRows: 4, maxRows: 9}"
                v-model="user.Remark"
                type="textarea"
                placeholder="个人简介"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div style="text-align:right;">
        <el-button type="danger" @click="dialogVisible=false">关闭</el-button>
        <el-button type="primary" @click="confirmUser">提交</el-button>
      </div>
    </el-dialog>

    <el-dialog
      :visible.sync="SGMWVisible"
      title="批量导入用户"
      :close-on-click-modal="false"
      @close="closePlatDialog"
      width="75%"
      top="6vh"
    >
      <template>
        <SGMWInfoUpload :dateText="randomNum" :ac="activeName" ref="USER"></SGMWInfoUpload>
      </template>
    </el-dialog>
  </div>
</template>

<style>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}

.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>

<script src="@/js/student/index.ts">

</script>